home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / FLAT.ZIP / FLATSEAR.C < prev    next >
C/C++ Source or Header  |  1993-06-19  |  12KB  |  426 lines

  1. #define WIN31
  2. #include <windows.h>
  3. /* For the fancy looking Borland dialog box routines */
  4. #ifdef USES_BWCC
  5. #include <bwcc.h>
  6. #endif
  7. #include "flatm.h"
  8. #pragma hdrstop
  9. #include "flatsear.h"
  10. #include "flatdata.h"
  11. #ifdef USES_MEMCHECK
  12. /* Memory checking routines  by StratosWare Corp. */
  13. #include "\wmemchec\memcheck.h"
  14. #endif
  15.  
  16. /*--------------------------------------------
  17. -
  18. -         FLATSEAR.C for Flat Windows Program
  19. -
  20. -        Routines to search the data base for 
  21. -          user selected search parameters 
  22. -
  23. -               Dennis R. Fischer
  24. -                 Denam Systems
  25. -          1115 Madison St. NE  Suite 226
  26. -              Salem, Oregon  97303
  27. -
  28. -             CompuServe 70405,1422
  29. -        Internet 70405.1422@compuserve.com
  30. -
  31. -        Developed with Borland 3.1 Compiler
  32. -
  33. -     Free for the taking but please give credit
  34. -                where credit is do
  35. -
  36. ----------------------------------------------*/              
  37.  
  38. static BOOL               bAll, bInvoice, bName, bCompany,
  39.                           bState, bCountry, bProduct, bYear;
  40. static struct tagFLATDATA FData;
  41.  
  42. void SetAllSearchs(HWND hwnd){
  43.     NulSearchData();
  44.     if (GetInvoiceSearch())
  45.         SetSearchString(hwnd, SearchForInvoice);
  46.     if (GetNameSearch())
  47.         SetSearchString(hwnd, SearchForName);
  48.     if (GetCompanySearch())
  49.         SetSearchString(hwnd, SearchForCompany);
  50.     if (GetStateSearch())
  51.         SetSearchString(hwnd, SearchForState);
  52.     if (GetCountrySearch())
  53.         SetSearchString(hwnd, SearchForCountry);
  54.     if (GetProductSearch())
  55.         SetSearchString(hwnd, SearchForProduct);
  56.     if (GetYearSearch())
  57.         SetSearchString(hwnd, SearchForYear);
  58. }
  59.  
  60. void GetSearchNameStr(LPSTR Name)
  61. {
  62.     lstrcat(Name, FData.Name);
  63. }
  64.  
  65. void GetSearchInvoiceStr(LPSTR Invoice)
  66. {
  67.     lstrcat(Invoice, FData.Invoice);
  68. }
  69.  
  70. void GetSearchCompanyStr(LPSTR Company)
  71. {
  72.     lstrcat(Company, FData.Company);
  73. }
  74.  
  75. void GetSearchStateStr(LPSTR State)
  76. {
  77.     lstrcat(State, FData.State);
  78. }
  79.  
  80. void GetSearchCountryStr(LPSTR Country)
  81. {
  82.     lstrcat(Country, FData.Country);
  83. }
  84.  
  85. void GetSearchProductStr(LPSTR Product)
  86. {
  87.     lstrcat(Product, FData.Product);
  88. }
  89.  
  90. void GetSearchYearStr(LPSTR Year)
  91. {
  92.     lstrcat(Year, FData.Year);
  93. }
  94.  
  95. BOOL GetAllSearch (void)
  96. {
  97.     return bAll;
  98. }
  99.  
  100. BOOL GetInvoiceSearch(void)
  101. {
  102.     return bInvoice;
  103. }
  104.  
  105. BOOL GetNameSearch (void)
  106. {
  107.     return bName;
  108. }
  109.  
  110. BOOL GetCompanySearch (void)
  111. {
  112.     return bCompany;
  113. }
  114.  
  115. BOOL GetStateSearch (void)
  116. {
  117.     return bState;
  118. }
  119.  
  120. BOOL GetCountrySearch (void)
  121. {
  122.     return bCountry;
  123. }
  124.  
  125. BOOL GetProductSearch (void)
  126. {
  127.     return bProduct;
  128. }
  129.  
  130. BOOL GetYearSearch (void)
  131. {
  132.     return bYear;
  133. }
  134.  
  135. void SetAllSearch (BOOL bSet)
  136. {
  137.     bAll = bSet;
  138. }
  139.  
  140. void SetInvoiceSearch (BOOL bSet)
  141. {
  142.     bInvoice = bSet;
  143. }
  144.  
  145. void SetNameSearch (BOOL bSet)
  146. {
  147.     bName = bSet;
  148. }
  149.  
  150. void SetCompanySearch (BOOL bSet)
  151. {
  152.     bCompany = bSet;
  153. }
  154.  
  155. void SetStateSearch (BOOL bSet)
  156. {
  157.     bState = bSet;
  158. }
  159.  
  160. void SetCountrySearch (BOOL bSet)
  161. {
  162.     bCountry = bSet;
  163. }
  164.  
  165. void SetProductSearch (BOOL bSet)
  166. {
  167.     bProduct = bSet;
  168. }
  169.  
  170. void SetYearSearch (BOOL bSet)
  171. {
  172.     bYear = bSet;
  173. }
  174.  
  175. void NulSearchData(void)
  176. {
  177.     NulData();
  178.     GetFlatData(&FData);
  179. }
  180.  
  181. void SetSearchString(HWND hwnd, SEARCHFORTYPE sfSearch)
  182. {
  183.     FARPROC fpSearch;
  184.   LPARAM  lParam;
  185.  
  186.     fpSearch = MakeProcInstance(SearchForProc, GetInstance());
  187.     if (fpSearch) {
  188.       lParam = MAKELPARAM(sfSearch, 0);
  189.         DialogBoxParam(GetInstance(), "DLG_SEARCHFOR", hwnd, fpSearch, lParam);
  190.         FreeProcInstance(fpSearch);
  191.     }
  192. }
  193.  
  194. #pragma argsused
  195. BOOL CALLBACK _export SearchForProc(HWND hDlg,
  196.                                                                         UINT message,
  197.                                                                         WPARAM wParam,
  198.                                                                         LPARAM lParam) {
  199. SEARCHFORTYPE static sfType;
  200. char ts[32];
  201.  
  202.     switch(message) { 
  203.         case WM_INITDIALOG:
  204.             sfType = LOWORD(lParam);
  205.             switch (sfType) {
  206.                 case SearchForInvoice:
  207.                     SetDlgItemText(hDlg, DLG_SEARCHFORSTR, " Invoice");
  208.                     SetDlgItemText(hDlg, DLG_SEARCHFORINPUT, "");
  209.                     SendDlgItemMessage(hDlg, DLG_SEARCHFORINPUT, EM_LIMITTEXT, 7, 0L);
  210.           break;
  211.                 case SearchForName:
  212.                     SetDlgItemText(hDlg, DLG_SEARCHFORSTR, " Name");
  213.                     SetDlgItemText(hDlg, DLG_SEARCHFORINPUT, "");
  214.                     SendDlgItemMessage(hDlg, DLG_SEARCHFORINPUT, EM_LIMITTEXT, 30, 0L);
  215.           break;
  216.                 case SearchForCompany:
  217.                     SetDlgItemText(hDlg, DLG_SEARCHFORSTR, " Company");
  218.                     SetDlgItemText(hDlg, DLG_SEARCHFORINPUT, "");
  219.                     SendDlgItemMessage(hDlg, DLG_SEARCHFORINPUT, EM_LIMITTEXT, 30, 0L);
  220.           break;
  221.                 case SearchForState:
  222.                     SetDlgItemText(hDlg, DLG_SEARCHFORSTR, " State");
  223.                     SetDlgItemText(hDlg, DLG_SEARCHFORINPUT, "");
  224.                     SendDlgItemMessage(hDlg, DLG_SEARCHFORINPUT, EM_LIMITTEXT, 2, 0L);
  225.           break;
  226.                 case SearchForCountry:
  227.                     SetDlgItemText(hDlg, DLG_SEARCHFORSTR, " Country");
  228.                     SetDlgItemText(hDlg, DLG_SEARCHFORINPUT, "");
  229.                     SendDlgItemMessage(hDlg, DLG_SEARCHFORINPUT, EM_LIMITTEXT, 15, 0L);
  230.           break;
  231.                 case SearchForProduct:
  232.                     SetDlgItemText(hDlg, DLG_SEARCHFORSTR, " Product");
  233.                     SetDlgItemText(hDlg, DLG_SEARCHFORINPUT, "");
  234.                     SendDlgItemMessage(hDlg, DLG_SEARCHFORINPUT, EM_LIMITTEXT, 12, 0L);
  235.           break;
  236.                 case SearchForYear:
  237.                     SetDlgItemText(hDlg, DLG_SEARCHFORSTR, " Year");
  238.                     SetDlgItemText(hDlg, DLG_SEARCHFORINPUT, "");
  239.                     SendDlgItemMessage(hDlg, DLG_SEARCHFORINPUT, EM_LIMITTEXT, 4, 0L);
  240.           break;
  241.                 default : break;
  242.       }
  243.             return TRUE;
  244.         case WM_COMMAND:
  245.             switch (wParam) {
  246.                 case IDOK:
  247.                     switch (sfType) {
  248.                         case SearchForInvoice:
  249.                             GetDlgItemText(hDlg, DLG_SEARCHFORINPUT, ts, 8);
  250.               lstrcpy(FData.Invoice, ts);
  251.               break;
  252.                         case SearchForName:
  253.                             GetDlgItemText(hDlg, DLG_SEARCHFORINPUT, ts, 31);
  254.               lstrcpy(FData.Name, ts);
  255.               break;
  256.                         case SearchForCompany:
  257.                             GetDlgItemText(hDlg, DLG_SEARCHFORINPUT, ts, 31);
  258.               lstrcpy(FData.Company, ts);
  259.               break;
  260.                         case SearchForState:
  261.                             GetDlgItemText(hDlg, DLG_SEARCHFORINPUT, ts, 3);
  262.               lstrcpy(FData.State, ts);
  263.               break;
  264.                         case SearchForCountry:
  265.                             GetDlgItemText(hDlg, DLG_SEARCHFORINPUT, ts, 16);
  266.               lstrcpy(FData.Country, ts);
  267.               break;
  268.                         case SearchForProduct:
  269.                             GetDlgItemText(hDlg, DLG_SEARCHFORINPUT, ts, 13);
  270.               lstrcpy(FData.Product, ts);
  271.               break;
  272.                         case SearchForYear:
  273.                             GetDlgItemText(hDlg, DLG_SEARCHFORINPUT, ts, 5);
  274.               lstrcpy(FData.Year, ts);
  275.               break;
  276.                         default : break;
  277.                     }
  278.                     EndDialog(hDlg, TRUE);
  279.                     return TRUE;
  280.  
  281.                 case IDCANCEL:
  282.                     EndDialog(hDlg, FALSE);
  283.                     return TRUE;
  284.             }
  285.             break;
  286.         }
  287.         return FALSE;
  288. }  /* SearchForProc */
  289.  
  290.  
  291. BOOL SetSearch(HWND hW)
  292. {
  293.     BOOL bDoit=FALSE;
  294.     FARPROC fpSearch;
  295.  
  296.     fpSearch = MakeProcInstance(SearchProc, GetInstance());
  297.     if (fpSearch) {
  298.         bDoit = DialogBox(GetInstance(), "DLG_SEARCH", hW, fpSearch);
  299.         FreeProcInstance(fpSearch);
  300.     }
  301.     return bDoit;
  302. }
  303.  
  304. #pragma argsused
  305. BOOL CALLBACK _export SearchProc(HWND hDlg,
  306.                                                                  UINT message,
  307.                                                                  WPARAM wParam,
  308.                                                                  LPARAM lParam) {
  309.     LRESULT lState;
  310.   WPARAM  nNewstate;
  311.     switch(message) {
  312.         case WM_INITDIALOG:
  313.             SendDlgItemMessage(hDlg, DLG_ALL, BM_SETCHECK, 1, 0L);
  314.             SendDlgItemMessage(hDlg, DLG_NAME, BM_SETCHECK, 0, 0L);
  315.             SendDlgItemMessage(hDlg, DLG_INVOICE2, BM_SETCHECK, 0, 0L);
  316.             SendDlgItemMessage(hDlg, DLG_COMPANY, BM_SETCHECK, 0, 0L);
  317.             SendDlgItemMessage(hDlg, DLG_STATE, BM_SETCHECK, 0, 0L);
  318.             SendDlgItemMessage(hDlg, DLG_COUNTRY, BM_SETCHECK, 0, 0L);
  319.             SendDlgItemMessage(hDlg, DLG_PRODUCT, BM_SETCHECK, 0, 0L);
  320.             SendDlgItemMessage(hDlg, DLG_YEAR, BM_SETCHECK, 0, 0L);
  321.             return TRUE;
  322.         case WM_COMMAND:
  323.             switch (wParam) {
  324.                 case DLG_ALL:
  325.                     SendDlgItemMessage(hDlg, DLG_ALL, BM_SETCHECK, 1, 0L);
  326.                     SendDlgItemMessage(hDlg, DLG_INVOICE2, BM_SETCHECK, 0, 0L);
  327.                     SendDlgItemMessage(hDlg, DLG_NAME, BM_SETCHECK, 0, 0L);
  328.                     SendDlgItemMessage(hDlg, DLG_COMPANY, BM_SETCHECK, 0, 0L);
  329.                     SendDlgItemMessage(